<div class="box">
    <div class="heading">
        <h1><img alt="" src="<?php echo base_url('assets/admin/images/setting.png'); ?>"> Theme Editor</h1>

        <?php if ($file_writable && $file_readable && $files_found): ?>
            <div class="buttons">
                <a class="button" href="#" onClick="$('#form').submit();"><span>Save</span></a>
            </div>
        <?php endif; ?>
    </div>
    <div class="content">
        <?php if ( ! $file_writable &&  ($files_found && $file_readable)): ?>
            <p class="attention">The current file does not have writable permissions.</p>
        <?php endif; ?>
        <div id="file_explorer">
            <ul>
                <li>
                    <div class="title">CMS Stylesheets</div>
                    <?php if ( ! empty($cmsstylesheets)): ?>
                    <ul>
                        <?php foreach($cmsstylesheets as $cmsstylesheet): ?>
                            <li>
                                <a <?php echo ($cmsstylesheet['theme_path'] == $file) ? 'class="selected"' : ''; ?> href="<?php echo site_url(ADMIN_PATH . '/tools/theme_editor/' . $cmsstylesheet['hash']); ?>">
                                    <?php echo $cmsstylesheet['title']; ?>
                                    <div class="filepath"><?php echo $cmsstylesheet['relative_path']; ?></div>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                    <?php endif; ?>
                </li>
				<li>
                    <div class="title">Admin Stylesheets</div>
                    <?php if ( ! empty($adminstylesheets)): ?>
                    <ul>
                        <?php foreach($adminstylesheets as $adminstylesheet): ?>
                            <li>
                                <a <?php echo ($adminstylesheet['theme_path'] == $file) ? 'class="selected"' : ''; ?> href="<?php echo site_url(ADMIN_PATH . '/tools/theme_editor/' . $adminstylesheet['hash']); ?>">
                                    <?php echo $adminstylesheet['title']; ?>
                                    <div class="filepath"><?php echo $adminstylesheet['relative_path']; ?></div>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                    <?php endif; ?>
                </li>
				<li>
                    <div class="title">CMS JavaScripts</div>
                    <?php if ( ! empty($cmsjavascripts)): ?>
                    <ul>
                        <li>
                            <?php foreach($cmsjavascripts as $cmsjavascript): ?>
                                <a <?php echo ($cmsjavascript['theme_path'] == $file) ? 'class="selected"' : ''; ?> href="<?php echo site_url(ADMIN_PATH . '/tools/theme_editor/' . $cmsjavascript['hash']); ?>">
                                    <?php echo $cmsjavascript['title']; ?>
                                    <div class="filepath"><?php echo $cmsjavascript['relative_path']; ?></div>
                                </a>
                            <?php endforeach; ?>
                        </li>
                    </ul>
                    <?php endif; ?>
                </li>
				<li>
                    <div class="title">Admin JavaScripts</div>
                    <?php if ( ! empty($adminjavascripts)): ?>
                    <ul>
                        <li>
                            <?php foreach($adminjavascripts as $adminjavascript): ?>
                                <a <?php echo ($adminjavascript['theme_path'] == $file) ? 'class="selected"' : ''; ?> href="<?php echo site_url(ADMIN_PATH . '/tools/theme_editor/' . $adminjavascript['hash']); ?>">
                                    <?php echo $adminjavascript['title']; ?>
                                    <div class="filepath"><?php echo $adminjavascript['relative_path']; ?></div>
                                </a>
                            <?php endforeach; ?>
                        </li>
                    </ul>
                    <?php endif; ?>
                </li>
                <li>
                    <div class="title">Template</div>
                    <?php if ( ! empty($templates)): ?>
                    <ul>
                        <?php foreach($templates as $template): ?>
                            <li>
                                <a <?php echo ($template['theme_path'] == $file) ? 'class="selected"' : ''; ?> href="<?php echo site_url(ADMIN_PATH . '/tools/theme_editor/' . $template['hash']); ?>">
                                    <?php echo $template['title']; ?>
                                    <div class="filepath"><?php echo $template['relative_path']; ?></div>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                    <?php endif; ?>
                </li>                
				<li>
                    <div class="title">Widgets</div>
                    <?php if ( ! empty($widgets)): ?>
                    <ul>
                        <li>
                            <?php foreach($widgets as $widget): ?>
                                <a <?php echo ($widget['theme_path'] == $file) ? 'class="selected"' : ''; ?> href="<?php echo site_url(ADMIN_PATH . '/tools/theme_editor/' . $widget['hash']); ?>">
                                    <?php echo $widget['title']; ?>
                                    <div class="filepath"><?php echo $widget['relative_path']; ?></div>
                                </a>
                            <?php endforeach; ?>
                        </li>
                    </ul>
                    <?php endif; ?>
                </li>
				<li>
                    <div class="title">CMS Views</div>
                    <?php if ( ! empty($cmsviews)): ?>
                    <ul>
                        <li>
                            <?php foreach($cmsviews as $cmsview): ?>
                                <a <?php echo ($cmsview['theme_path'] == $file) ? 'class="selected"' : ''; ?> href="<?php echo site_url(ADMIN_PATH . '/tools/theme_editor/' . $cmsview['hash']); ?>">
                                    <?php echo $cmsview['title']; ?>
                                    <div class="filepath"><?php echo $cmsview['relative_path']; ?></div>
                                </a>
                            <?php endforeach; ?>
                        </li>
                    </ul>
                    <?php endif; ?>
                </li>
				<li>
                    <div class="title">Admin Views</div>
                    <?php if ( ! empty($adminviews)): ?>
                    <ul>
                        <li>
                            <?php foreach($adminviews as $adminview): ?>
                                <a <?php echo ($adminview['theme_path'] == $file) ? 'class="selected"' : ''; ?> href="<?php echo site_url(ADMIN_PATH . '/tools/theme_editor/' . $adminview['hash']); ?>">
                                    <?php echo $adminview['title']; ?>
                                    <div class="filepath"><?php echo $adminview['relative_path']; ?></div>
                                </a>
                            <?php endforeach; ?>
                        </li>
                    </ul>
                    <?php endif; ?>
                </li>
            </ul>
        </div>
        <div style="margin-right: 230px;">
            <?php if ( ! $files_found): ?>
                <p class="attention">No files were found for this theme.</p>
            <?php elseif ( ! $file_readable): ?>
                <p class="error">The attempted file does not exist or does not have readable permissions.</p>
            <?php else: ?>
                <?php echo form_open(null, 'id="form"'); ?>
                    <?php echo form_textarea(array('name'=>'code', 'id'=>'code', 'value'=>set_value('code', $code))); ?>
                <?php echo form_close(); ?>
              
                <script type="text/javascript">
                    $(document).ready( function() {
                        var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
                            lineNumbers: true,
                            matchBrackets: true,
                            mode: "<?php echo $mode; ?>",
                            indentUnit: 4,
                            indentWithTabs: true,
                            enterMode: "keep",
                            tabMode: "shift"
                        });
                    });
                </script>
                
            <?php endif; ?>
        </div>
        <div class="clear"></div>
    </div>
</div>
